package com.xiaoran.RMQ_1.test6_Direct_exchange;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.xiaoran.RMQ_1.utlis.RabbitMqUtils;

public class Direct_exchange_Consumer_2 {
    public static final String EXCHANGE_NAME="direct_logs";
    public static void main(String args[]) throws  Exception{
        System.out.println("我是error和warning打印出消息");

        Channel channel=RabbitMqUtils.getChannel();
        //声明一个交换机
        channel.exchangeDeclare(EXCHANGE_NAME,BuiltinExchangeType.DIRECT);
        //声明一个队列
        channel.queueDeclare("console",false,false,false,null);
        //绑定交换机与队列
        channel.queueBind("console",EXCHANGE_NAME,"error");
        channel.queueBind("console",EXCHANGE_NAME,"warning");

        //接收消息
        DeliverCallback deliverCallback=(consumerTag, message)->{
            System.out.println("我是error和warning打印出消息"+new String(message.getBody()));
        };
        channel.basicConsume("console",true,deliverCallback,consumerTag->{});
    }
}

